package com.test.qnews.activity;

import android.content.Intent;
import android.graphics.Color;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;

import com.test.qnews.R;

import com.test.qnews.adapter.StarAdapter;
import com.test.qnews.beans.StarBeans;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by dllo on 16/1/18.
 */
public class StarActivity extends BaseActivity implements View.OnClickListener {
    private List<StarBeans> data;
    private StarAdapter starAdapter;
    private ListView listView;
    private Button hot, taiwan, dalu, japan, europe;

    @Override
    protected int setLayout() {
        return R.layout.activity_star;
    }

    @Override
    protected void initView() {

        listView = (ListView) findViewById(R.id.listview_star);
        data = new ArrayList<>();

        hot = (Button) findViewById(R.id.btn_hot);
//        europe = (Button) findViewById(R.id.btn_europe);
        japan = (Button) findViewById(R.id.btn_japan);
//        taiwan = (Button) findViewById(R.id.btn_taiwan);
//        dalu = (Button) findViewById(R.id.btn_dalu);

        hot.setOnClickListener(this);
//        europe.setOnClickListener(this);
        japan.setOnClickListener(this);
//        taiwan.setOnClickListener(this);
//        dalu.setOnClickListener(this);

        data.add(new StarBeans(R.mipmap.person1, "罗志祥"));
        data.add(new StarBeans(R.mipmap.person1, "王力宏"));
//        data.add(new StarBeans(R.mipmap.person1, "林俊杰"));
//        data.add(new StarBeans(R.mipmap.person1, "王菲"));

        starAdapter = new StarAdapter(data, this);
        listView.setAdapter(starAdapter);
//        listView.setOnItemClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_hot:
                data = new ArrayList<>();
                data.add(new StarBeans(R.mipmap.person1, "罗志祥"));
                data.add(new StarBeans(R.mipmap.person1, "王力宏"));
//                data.add(new StarBeans(R.mipmap.person1, "林俊杰"));
//                data.add(new StarBeans(R.mipmap.person1, "王菲"));

                starAdapter.refreshData(data);
                hot.setBackgroundColor(Color.WHITE);
//                europe.setBackgroundColor(Color.parseColor("#CDCECE"));
                japan.setBackgroundColor(Color.parseColor("#CDCECE"));
//                dalu.setBackgroundColor(Color.parseColor("#CDCECE"));
//                taiwan.setBackgroundColor(Color.parseColor("#CDCECE"));

                listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                        if (position == 0) {
                            String urlDy = "http://zzd.sm.cn/appservice/api/v1/articles?client_os=android&client_" +
                                    "version=2.1.0.1&bid=800&m_ch=006&city=0411&sn=10d5c82630e5931bf2562db691499" +
                                    "e0f&aid=%5B%2216643993748250654912%22%2C%229891432432094299213%22%2C%221417" +
                                    "7131633246006022%22%2C%226052974322560735203%22%2C%229619182808806695461%22" +
                                    "%2C%228095594890224441518%22%2C%227489410067220851999%22%2C%228509162545074" +
                                    "281227%22%2C%227138365999269576010%22%2C%226373645797431383289%22%2C%2211680" +
                                    "977588489723817%22%2C%2211945680315780834163%22%2C%2213921859809516640037%22" +
                                    "%2C%221955103711273649090%22%2C%227812272277897574190%22%2C%2281502558506874" +
                                    "88830%22%2C%229174618316062159223%22%2C%229361892582258926332%22%2C%22159309" +
                                    "37274512054368%22%2C%2217742141791779574030%22%5D";
                            String urlMi = "http://zzd.sm.cn/appservice/api/v1/card/230/detail?client_os=android&c" +
                                    "lient_version=2.1.0.1&bid=800&m_ch=006&city=0411&sn=10d5c82630e5931bf2562db691" +
                                    "499e0f";
                            Intent intent = new Intent(StarActivity.this, StarPersonActivity.class);
                            intent.putExtra("urlDy" + position, urlDy);
                            intent.putExtra("urlMi" + position, urlMi);
                            intent.putExtra("pos", position);
                            startActivity(intent);
                        }
                        if (position == 1) {
                            String urlDy = "http://zzd.sm.cn/appservice/api/v1/articles?client_os=android&client_" +
                                    "version=2.1.0.1&bid=800&m_ch=006&city=0411&sn=10d5c82630e5931bf2562db691499" +
                                    "e0f&aid=%5B%2216643993748250654912%22%2C%229891432432094299213%22%2C%221417" +
                                    "7131633246006022%22%2C%226052974322560735203%22%2C%229619182808806695461%22" +
                                    "%2C%228095594890224441518%22%2C%227489410067220851999%22%2C%228509162545074" +
                                    "281227%22%2C%227138365999269576010%22%2C%226373645797431383289%22%2C%2211680" +
                                    "977588489723817%22%2C%2211945680315780834163%22%2C%2213921859809516640037%22" +
                                    "%2C%221955103711273649090%22%2C%227812272277897574190%22%2C%2281502558506874" +
                                    "88830%22%2C%229174618316062159223%22%2C%229361892582258926332%22%2C%22159309" +
                                    "37274512054368%22%2C%2217742141791779574030%22%5D";
                            String urlMi = "http://zzd.sm.cn/appservice/api/v1/card/230/detail?client_os=android&c" +
                                    "lient_version=2.1.0.1&bid=800&m_ch=006&city=0411&sn=10d5c82630e5931bf2562db691" +
                                    "499e0f";
                            Intent intent = new Intent(StarActivity.this, StarPersonActivity.class);
                            intent.putExtra("urlDy" + position, urlDy);
                            intent.putExtra("urlMi" + position, urlMi);
                            intent.putExtra("pos", position);
                            startActivity(intent);
                        }
                    }
                });

                break;
            case R.id.btn_japan:
                data = new ArrayList<>();
                data.add(new StarBeans(R.mipmap.person1, "尼坤"));
                data.add(new StarBeans(R.mipmap.person1, "蔡妍"));
//                data.add(new StarBeans(R.mipmap.person1, "朴信惠"));
                starAdapter.refreshData(data);

                japan.setBackgroundColor(Color.WHITE);
//                europe.setBackgroundColor(Color.parseColor("#CDCECE"));
                hot.setBackgroundColor(Color.parseColor("#CDCECE"));
//                dalu.setBackgroundColor(Color.parseColor("#CDCECE"));
//                taiwan.setBackgroundColor(Color.parseColor("#CDCECE"));
                listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                        if (position == 0) {
                            position = position + 3;
                            String urlDy = "http://zzd.sm.cn/appservice/api/v1/articles?client_os=android&client_" +
                                    "version=2.1.0.1&bid=800&m_ch=006&city=0411&sn=10d5c82630e5931bf2562db691499" +
                                    "e0f&aid=%5B%2216643993748250654912%22%2C%229891432432094299213%22%2C%221417" +
                                    "7131633246006022%22%2C%226052974322560735203%22%2C%229619182808806695461%22" +
                                    "%2C%228095594890224441518%22%2C%227489410067220851999%22%2C%228509162545074" +
                                    "281227%22%2C%227138365999269576010%22%2C%226373645797431383289%22%2C%2211680" +
                                    "977588489723817%22%2C%2211945680315780834163%22%2C%2213921859809516640037%22" +
                                    "%2C%221955103711273649090%22%2C%227812272277897574190%22%2C%2281502558506874" +
                                    "88830%22%2C%229174618316062159223%22%2C%229361892582258926332%22%2C%22159309" +
                                    "37274512054368%22%2C%2217742141791779574030%22%5D";
                            String urlMi = "http://zzd.sm.cn/appservice/api/v1/card/230/detail?client_os=android&c" +
                                    "lient_version=2.1.0.1&bid=800&m_ch=006&city=0411&sn=10d5c82630e5931bf2562db691" +
                                    "499e0f";
                            Intent intent = new Intent(StarActivity.this, StarPersonActivity.class);
                            intent.putExtra("urlDy" + position , urlDy);
                            intent.putExtra("urlMi" + position , urlMi);
                            intent.putExtra("pos", position);
                            startActivity(intent);
                        }
                        if (position == 1) {
                            position = position + 4;

                            String urlDy = "http://zzd.sm.cn/appservice/api/v1/articles?client_os=android&client_" +
                                    "version=2.1.0.1&bid=800&m_ch=006&city=0411&sn=10d5c82630e5931bf2562db691499" +
                                    "e0f&aid=%5B%2216643993748250654912%22%2C%229891432432094299213%22%2C%221417" +
                                    "7131633246006022%22%2C%226052974322560735203%22%2C%229619182808806695461%22" +
                                    "%2C%228095594890224441518%22%2C%227489410067220851999%22%2C%228509162545074" +
                                    "281227%22%2C%227138365999269576010%22%2C%226373645797431383289%22%2C%2211680" +
                                    "977588489723817%22%2C%2211945680315780834163%22%2C%2213921859809516640037%22" +
                                    "%2C%221955103711273649090%22%2C%227812272277897574190%22%2C%2281502558506874" +
                                    "88830%22%2C%229174618316062159223%22%2C%229361892582258926332%22%2C%22159309" +
                                    "37274512054368%22%2C%2217742141791779574030%22%5D";
                            String urlMi = "http://zzd.sm.cn/appservice/api/v1/card/230/detail?client_os=android&c" +
                                    "lient_version=2.1.0.1&bid=800&m_ch=006&city=0411&sn=10d5c82630e5931bf2562db691" +
                                    "499e0f";
                            Intent intent = new Intent(StarActivity.this, StarPersonActivity.class);
                            intent.putExtra("urlDy" + position , urlDy);
                            intent.putExtra("urlMi" + position , urlMi);
                            intent.putExtra("pos", position);
                            startActivity(intent);
                        }
                    }
                });




                break;
//            case R.id.btn_taiwan:
//                data = new ArrayList<>();
//                data.add(new StarBeans(R.mipmap.person1, "孙燕姿"));
//                data.add(new StarBeans(R.mipmap.person1, "林志颖"));
//                data.add(new StarBeans(R.mipmap.person1, "王力宏"));
//
//                starAdapter.refreshData(data);
//                taiwan.setBackgroundColor(Color.WHITE);
//                europe.setBackgroundColor(Color.parseColor("#CDCECE"));
//                hot.setBackgroundColor(Color.parseColor("#CDCECE"));
//                dalu.setBackgroundColor(Color.parseColor("#CDCECE"));
//                japan.setBackgroundColor(Color.parseColor("#CDCECE"));
//                break;

        }
    }

//    @Override
//    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//        if (position == 0){
//            String urlDy = "http://zzd.sm.cn/appservice/api/v1/articles?client_os=android&client_" +
//                    "version=2.1.0.1&bid=800&m_ch=006&city=0411&sn=10d5c82630e5931bf2562db691499" +
//                    "e0f&aid=%5B%2216643993748250654912%22%2C%229891432432094299213%22%2C%221417" +
//                    "7131633246006022%22%2C%226052974322560735203%22%2C%229619182808806695461%22" +
//                    "%2C%228095594890224441518%22%2C%227489410067220851999%22%2C%228509162545074" +
//                    "281227%22%2C%227138365999269576010%22%2C%226373645797431383289%22%2C%2211680" +
//                    "977588489723817%22%2C%2211945680315780834163%22%2C%2213921859809516640037%22" +
//                    "%2C%221955103711273649090%22%2C%227812272277897574190%22%2C%2281502558506874" +
//                    "88830%22%2C%229174618316062159223%22%2C%229361892582258926332%22%2C%22159309" +
//                    "37274512054368%22%2C%2217742141791779574030%22%5D";
//            String urlMi = "http://zzd.sm.cn/appservice/api/v1/card/230/detail?client_os=android&c" +
//                    "lient_version=2.1.0.1&bid=800&m_ch=006&city=0411&sn=10d5c82630e5931bf2562db691" +
//                    "499e0f";
//            Intent intent = new Intent(this,StarPersonActivity.class);
//            intent.putExtra("urlDy",urlDy);
//            intent.putExtra("urlMi",urlMi);
//            startActivity(intent);
//        }
//    }

}
